package com.cm.sys.framework.utils;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cm.sys.system.dao.BaseDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @author yxq18
 *
 */
@Component
public class PageList {

    @Autowired
    private BaseDao baseDao;
    @Autowired
    private PageHelperUtil pageHelperUtil;

    /***
     * 初始化分页
     * 
     * @param pageIndex
     * @param pageSize
     * @param Class
     */
    public void initPage(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);

    }

    public Map<String, Object> getData(PageData pageData, String sql, Object[] args) {
        PageHelper.startPage(pageData.getPageIndex(), pageData.getPageSize());
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(baseDao.getListMap(sql, args));
        return pageHelperUtil.getPageinfo(pageInfo);

    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    public Map<String, Object> getData(List list, Class Class) {
        PageInfo<Class> pageInfo = new PageInfo<>(list);
        return pageHelperUtil.getPageinfo(pageInfo);
    }

}
